package com.bjpowernode.web.views;

import com.bjpowernode.enums.Code;
import com.bjpowernode.web.vo.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;


//ajax请求返回的工具
@ApiModel("Ajax请求返回结果类")
public class ResultView<T> {
    @ApiModelProperty(value = "应答码")
    private int code;//应答码，10000 成功;20000 失败
    @ApiModelProperty(value = "文本说明")
    private String msg;//消息文本
    @ApiModelProperty(value = "单个数据")
    private Object object;//单个对象的数据
    @ApiModelProperty(value = "列表数据")
    private List<T> list;//多个数据
    @ApiModelProperty(value = "分页对象")
    private Page page;//分页
    @ApiModelProperty(value = "访问token")
    private String accessToken;

    public ResultView() {
    }

    public ResultView(int code, String msg, Object object) {
        this.code = code;
        this.msg = msg;
        this.object = object;
    }

    //创建一个表示成功的ResultView对象
    public static ResultView SUCCESS() {
        ResultView resultView = new ResultView();
        resultView.setEnumCode(Code.SUCCESS);
        resultView.setObject("");
        return resultView;
    }

    //创建一个表示失败的ResultView对象
    public static ResultView FAIL() {
        ResultView resultView = new ResultView();
        resultView.setEnumCode(Code.FAILURE);
        resultView.setObject("");
        return resultView;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public void setEnumCode(Code code) {
        this.code = code.getCode();
        this.msg = code.getText();
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getObject() {
        return object;
    }

    public void setObject(Object object) {
        this.object = object;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
}
